cmake_minimum_required(VERSION 3.14)

project(kylin-process-manager LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_definitions(-DQT_NO_KEYWORDS)
#set(QAPPLICATION_CLASS QApplication1 CACHE STRING "Inheritance class for SingleApplication")

find_package(PkgConfig REQUIRED)
find_package(KF5KIO)
find_package(KF5WindowSystem)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Widgets DBus)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets DBus)

pkg_check_modules(KYSDKWAYLANDHELPER_PKG kysdk-waylandhelper)
pkg_check_modules(GIO REQUIRED gio-unix-2.0)

include_directories(${GIO_INCLUDE_DIRS})
include_directories(src src/core src/utils src/dbusinterfaces src/dbusservices)
include_directories(../)

set (SRC_Sources
    src/core/appcgroup.cpp
    src/core/appinfo.cpp
    src/core/appinfomanager.cpp
    src/core/appstatusmanager.cpp
    src/core/basecontroller.cpp
    src/core/eventwatcher.cpp
    src/core/policy.cpp
    src/core/timerwheel.cpp
    src/dbusinterfaces/statusmanagerinterface.cpp
    src/main.cpp
    src/appmanager.cpp
    src/dbusinterfaces/cgroupinterface.cpp
    src/dbusinterfaces/kwininterface.cpp
    src/dbusservices/applauncher.cpp
    src/dbusservices/applauncherdaemon.cpp
    src/dbusservices/appmanagerservice.cpp
    src/dbusservices/whitelistmanager.cpp
    src/memorymonitor.cpp
    src/utils/misc.cpp
    src/utils/processinfo.cpp
)

set (SRC_Headers
    src/core/appcgroup.h
    src/core/appinfo.h
    src/core/appinfomanager.h
    src/core/appstatusmanager.h
    src/core/basecontroller.h
    src/core/eventwatcher.h
    src/core/policy.h
    src/core/timerwheel.h
    src/dbusinterfaces/statusmanagerinterface.h
    src/appmanager.h
    src/dbusinterfaces/cgroupinterface.h
    src/dbusinterfaces/kwininterface.h
    src/dbusservices/applauncher.h
    src/dbusservices/applauncherdaemon.h
    src/dbusservices/appmanagerservice.h
    src/dbusservices/whitelistmanager.h
    src/memorymonitor.h
    src/utils/misc.h
    src/utils/processinfo.h)

qt5_add_dbus_interface(SRC_Sources configs/com.kylin.ProcessManager.xml processmanagerinterface)

add_executable(kylin-process-manager
  ${SRC_Sources}
  ${SRC_Headers}
)

target_include_directories(kylin-process-manager PRIVATE ${KYSDKWAYLANDHELPER_PKG_INCLUDE_DIRS})
target_link_directories(kylin-process-manager PRIVATE ${KYSDKWAYLANDHELPER_PKG_LIBRARY_DIRS})

target_link_libraries(kylin-process-manager
    Qt${QT_VERSION_MAJOR}::Core
    Qt${QT_VERSION_MAJOR}::Widgets
    Qt${QT_VERSION_MAJOR}::DBus
    ${GIO_LIBRARIES}
    ${KYSDKWAYLANDHELPER_PKG_LIBRARIES}
    KF5::KIOCore
    KF5::WindowSystem
    SingleApplication::SingleApplication
    cgroup
    proc2
    spdlog
    ukui-log4qt)

install(TARGETS kylin-process-manager DESTINATION /usr/bin)
